#!/bin/bash

# 脚本所在路径：/usr/local/snowfield/script/lb_bootStart.sh
# 在操作系统开机时启动与负载均衡相关的服务
# 1.开机启动keepalived
# 2.开机启动haproxy,如果haproxy进程未启动，则启动;
#

kaPidCnt=$(ps ax | grep "/keepalived" | grep -v grep | wc -l)
#echo kaPidCnt:$kaPidCnt
if [ $kaPidCnt == 0 ];then
  /usr/sbin/service keepalived start
  if [ $? -ne 0 ]; then
      echo "boot start keepalived error, please check."
  fi
fi

haPidCnt=$(ps ax | grep "/usr/sbin/haproxy" | grep -v grep | wc -l)
#echo haPidCnt:haPidCnt
if [ $haPidCnt == 0 ];then
  /usr/bin/systemctl start haproxy.service
  if [ $? -ne 0 ]; then
      echo "boot start haproxy.service error, please check."
  fi
fi
